/* Copyright 2014 Jan Wolter */
#include "stack.h"
#include "stock.h"
#include "found.h"
#include "waste.h"
#include "solve.h"
#include "game.h"

char *gamename= "Consecutive Card Counting";
char *gameopt= "";
Stack *gathered= NULL;
Stack *temp= NULL;

int nplayed= 0;
int ncon= 0;

void setopt(char c) {}

/* This is the main program for setting up the current game */
void exec(int gather, int arif, int over, int cut)
{
    /* Could set things like ndeck, nsuit here */

    if (verbose > 2 && gathered != NULL) printStack(stdout,"Start",gathered);

    /* Build and shuffle the deck */
    Stack *shuf= mixcards(arif, over, cut);

    int pos[52];

    if (verbose > 2) printStack(stdout,"Deck",shuf);

    int con= 0;
    for (int i= 0; i < ncard-1; i++)
	if (shuf->c[i] == shuf->c[i+1]+1 ||
	    shuf->c[i] == shuf->c[i+1]-1)
	    con++;
    if (verbose > 2) printf("Cons=%d\n",con);
    ncon+= con;
    nplayed++;
}

void gatherAll()
{
    if (gathered != NULL) freeStack(gathered);
    gathered= NULL;
}

void printState(FILE *f, Stack *stks)
{
}

int fdone(int k)
{
    return 1;
}

int victory()
{
    return 1;
}

int quality()
{
    return 0;
}


void summary()
{
    printf("Played:      %d games\n",nplayed);
    printf("Consecutive: %.4f\n",(float)ncon/nplayed);
}
